from django.shortcuts import render
from django.http import HttpResponse

# Create your views here.
from .models import Article

# `exact`: 用于大小写敏感的精确匹配。
def querry1(request):
    article = Article.objects.filter(id__exact=1)
    # 上面的等价于下面这条
    # Article.objects.filter(id=1)
    # 查看底层执行的sql语句：查询结果.query
    print(article.query)
    print(article)
    return HttpResponse("查询成功！")

# `iexact`: 用于大小写不敏感的精确匹配。
def  querry2(request):
    article = Article.objects.filter(title__iexact="hello world")
    return HttpResponse("查询成功！")

# contains是一个用于执行区分大小写的包含查询的过滤器
def querry3(request):
    article = Article.objects.filter(title__contains="hello world")
    return HttpResponse("查询成功！")

# icontains是一个用于执行不区分大小写的包含查询的过滤器
def querry4(request):
    article = Article.objects.filter(title__icontains="hello world")
    return HttpResponse("查询成功！")

def querry5(request):
    article = Article.objects.filter(title__in=[1,2,3])
    return HttpResponse("查询成功！")